﻿@model Submission
@{
    ViewData["Title"] = $"Submission s{Model.Id}: {Model.Name}";
    int t = 0, t2 = 0;
}

<h2 class="mt-2">@ViewData["Title"]</h2>

<!-- ace editor -->
<script src="/lib/ace/ace.js"></script>
<script src="/lib/ace/ext-modelist.js"></script>

<ul class="nav nav-tabs source-tab-nav">
    @foreach (var item in Model.Files)
    {
        int id = t++;
        <li class="nav-item">
            <a class="nav-link @(id > 0 ? "" : "active")" data-toggle="tab"
               href="#source-@(id)" role="tab">@item.FileId:@item.FilePath</a>
        </li>
    }
</ul>

<div class="tab-content source-tab">
    @foreach (var item in Model.Files)
    {
        int id = t2++;
        string idd = "source" + id;
        <div class="editor tab-pane fade @(id == 0 ? "show active" : "")" id="@idd" role="tabpanel" style="font-size:0.8em">@item.Content</div>
        <script>
            $(function () {
                var @idd = ace.edit("@idd");
                @(idd).setTheme("ace/theme/eclipse");
                @(idd).setOptions({ maxLines: Infinity });
                @(idd).setReadOnly(true);
                var modelist = ace.require('ace/ext/modelist');
                var filePath = "@(item.FileName)";
                var mode = modelist.getModeForPath(filePath).mode;
                @(idd).getSession().setMode(mode);
                document.getElementById("@(idd)").editor = @(idd);
            });
        </script>
    }
</div>
